package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.pojo.Expend;
import com.neuedu.mapper.ExpendMapper;
import com.neuedu.pojo.Income;
import com.neuedu.service.IExpendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.util.CommonResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wk
 * @since 2020-09-23
 */
@Service
public class ExpendServiceImpl extends ServiceImpl<ExpendMapper, Expend> implements IExpendService {

    @Override
    public CommonResult list(Expend expend) {
        QueryWrapper<Expend> qu=new QueryWrapper<>();
        if(expend.getActive()!=null){
            qu.eq("active",expend.getActive());
        }
        if(expend.getTypeId()!=null&&expend.getTypeId()!=1000){
            qu.eq("type_id",expend.getTypeId());
        }
        if(!StringUtils.isBlank(expend.getItemName())){
            if(!"1000".equals(expend.getItemName()))
            qu.eq("item_name",expend.getItemName());
        }
        //如果在LocalDate转化器处设置可以接收到空，所以加条件时候，则判断第一个位置是不是null//即[null]
        if(expend.getDateRange()!=null&&expend.getDateRange().length>0&&expend.getDateRange()[0]!=null){
            System.out.println("进入！！！！！！！！！！");
            LocalDate[] arr=expend.getDateRange();
            qu.between("out_date",arr[0],arr[1]);
        }
        if(!StringUtils.isBlank(expend.getPosterName())){
            qu.like("poster_name",expend.getPosterName());
        }
        if(!StringUtils.isBlank(expend.getGetterName())){
            qu.like("getter_name",expend.getGetterName());
        }
        if(expend.getIfpage()==1){
            return CommonResult.success(this.page(new Page<Expend>(expend.getPageNo(),expend.getPageSize()),qu));
            //return CommonResult.success(this.page(new Page<Income>(income.getPageNo(), income.getPageSize()),qu));
        }else {
            return CommonResult.success(this.list(qu));
        }
    }
}
